#!/bin/sh

MOUNT="/media/DISK_A1/system"

export PATH=$MOUNT/bin:$MOUNT/sbin:$MOUNT/usr/bin:$MOUNT/usr/sbin:/sbin:/usr/sbin:/bin:/usr/bin
export LD_LIBRARY_PATH=$MOUNT/lib:$MOUNT/usr/lib:/lib:/usr/lib

start() {

	umount /web > /dev/null 2>&1
	. /etc/version
	V1=$BUILD_CODE
	if [ -f $MOUNT/web/version ]
	then
	    . $MOUNT/web/version
	    V2=$BUILD_CODE
	else
	    V2=""
	fi

	if [ "$V1" != "$V2" ]
	then
		echo "Copying /web"
		cp -rf /web $MOUNT/
		cp -f /etc/version $MOUNT/web/
		update_sidebar.lua
	fi
	mount --bind $MOUNT/web /web
	mini_inetd 81 in.www $mount/web/ 2>&1 &
}
    
stop() {
	killall mini_inetd
	umount /web
}
	
case "$1" in
    start)
        start
        ;;
    stop)
        stop
        ;;
    restart)
        stop
        start
	;;
    *)
	echo "Usage: $0 {start|stop|restart}"
	;;
esac
